package com.heima.wemedia.controller.v1;

import com.heima.common.dtos.ResponseResult;
import com.heima.wemedia.dto.WmPageRequestDto;
import com.heima.wemedia.service.WmMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController {

    @Autowired
    private WmMaterialService wmMaterialService;

    /**
     * 上传图片至minio，并将路径写进数据库
     */
    @PostMapping("/upload_picture")
    public ResponseResult upLoadPicture(MultipartFile multipartFile){
        return wmMaterialService.upLoadPicture(multipartFile);
    }

    /**
     * 图片列表查看
     */
    @PostMapping("/list")
    public ResponseResult pictureList(@RequestBody WmPageRequestDto wmPageRequestDto){
        return wmMaterialService.photoList(wmPageRequestDto);
    }

    /**
     * 图片收藏，图片id为路径变量
     */
    @GetMapping("/collect/{pid}")
    public void pictureCollect(@PathVariable("pid") Integer pid){
        //System.out.println(pid);
        wmMaterialService.photoCollect(pid);
    }

    /**
     * 图片取消收藏
     */
    @GetMapping("/cancel_collect/{pid}")
    public void pictureUnCollect(@PathVariable("pid") Integer pid){
        //System.out.println(pid);
        wmMaterialService.cancelCollect(pid);
    }

    /**
     * 删除图片，这里只是删除数据库中的地址
     * 并没有删除minio中实际的图片
     */
    @GetMapping("/del_picture/{pid}")
    public void delPicture(@PathVariable("pid") Integer pid){
        //System.out.println(pid);
        wmMaterialService.delPhoto(pid);
    }

}
